package com.ody.util.code;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class CodeContext {
    protected Map<String, Object> ctxMap = new HashMap<>();

	public Map<String, Object> getCtxMap() {
		return Collections.unmodifiableMap(ctxMap);
	}

	public String replace(String s) {
		return PlaceHolderHelper.replace(s, ctxMap);
	}
	
	public CodeContext set(String key, Object value) {
		ctxMap.put(key, value);
		return this;
	}
	
	@Override
	public CodeContext clone() {
		CodeContext ctx = new CodeContext();
		for (Entry<String, Object> entry : ctxMap.entrySet()) {
			ctx.set(entry.getKey(), entry.getValue());
		}
		return ctx;
	}

	@Override
	public String toString() {
		return ctxMap.toString();
	}
}
